﻿using CB.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using Swift;
using UnityEngine.EventSystems;

namespace CB.Client
{
    public static class UIUtils
    {
        public static Color GetColor(this BColor bc)
        {
            switch (bc)
            {
                case BColor.Red:
                    return Color.red;
                case BColor.Blue:
                    return Color.blue;
                case BColor.Yellow:
                    return Color.yellow;
                case BColor.Black:
                    return new Color(0, 0, 0);
                case BColor.Purple:
                    return new Color(255, 0, 255);
                case BColor.Green:
                    return Color.green;
                case BColor.None:
                default:
                    return Color.white;
            }
        }

        public static string GetRandomGameImage(SRandom srand)
        {
            var ss = Resources.LoadAll<Texture2D>("UI/ImageGame");
            var s = ss.GetRandomOne(srand);
            return s.name;
        }

        public static void ShowTransit(this UIContent ui, Action action_During = null, Action action_After = null)
        {
            UIManager.Instance.ShowUIContent<Transit>(UIContentDefine.Transit, LayerType.Top).ShowTransitAndAction(action_During, action_After);
        }

        public static bool CheckGuiRaycastObjects(this MonoBehaviour mb)
        {
            var raycaster = Camera.main.transform.root.GetComponentInChildren<GraphicRaycaster>();
            var evnSystem = Camera.main.transform.root.GetComponentInChildren<EventSystem>();
            if (evnSystem == null)
                return false;

            var eventData = new PointerEventData(evnSystem)
            {
                pressPosition = Input.mousePosition,
                position = Input.mousePosition
            };

            var list = new List<RaycastResult>();
            raycaster.Raycast(eventData, list);
            return list.Count > 0;
        }
    }
}
